# event
from EventDefine import event_MAINMENU, event_SINGLEPLAYER_BACKTOMAINMENU, \
                                  event_SINGLEPLAYER_MENU, \
                                  event_SINGLEPLAYER_NEWGAME, event_SINGLEPLAYER_LOADGAME, \
                                  event_SINGLEPLAYER_REPLY
# gui
from Shell.gui.SinglePlayerGameMenuFrame import SinglePlayerGameMenuFrame
# fsm
from direct.fsm import FSM
from Cube.gui.PreludeFinale import FSMExtend as PreludeFinaleFSM

class SingleGameMenuFSM(FSM.FSM, PreludeFinaleFSM):
    def __init__(self):
        FSM.FSM.__init__(self, name = 'single game menu')

        self.demand('SinglePlayerGameMenu')

    def enterSinglePlayerGameMenu(self):
        self.SinglePlayerGameMenuFrame = SinglePlayerGameMenuFrame()
        self.acceptOnce(event_SINGLEPLAYER_NEWGAME, self.demand, ["NewGameLoader"])
        #self.acceptOnce(event_SINGLEPLAYER_LOADGAME, self.demand, ["LoadGameLoader"])
        #self.acceptOnce(event_SINGLEPLAYER_REPLY, self.demand, ["ReplayLoader"])
        self.acceptOnce(event_SINGLEPLAYER_BACKTOMAINMENU, self.demand, ["MainMenu"])

    def exitSinglePlayerGameMenu(self):
        self.ignoreAll()
        self.SinglePlayerGameMenuFrame.destroy()

    def filterSinglePlayerGameMenu(self, request, args):
        self.NextStateSet(request)   # transfer to wait state
        return self.WaitFinaleState

    def enterNewGameLoader(self):
        #self.acceptOnce(event_SINGLEPLAYERGAME, self.demand, ["Menu"]) # enter Menu state
        self.acceptOnce(event_SINGLEPLAYER_MENU, self.demand, ["SinglePlayerGameMenu"]) # enter Menu state

    def exitNewGameLoader(self):
        self.ignoreAll()

    def enterLoadGameLoader(self):
        #self.acceptOnce(event_SINGLEPLAYERGAME, self.demand, ["Menu"]) # enter Menu state
        self.acceptOnce(event_SINGLEPLAYER_MENU, self.demand, ["SinglePlayerGameMenu"]) # enter Menu state

    def exitLoadGameLoader(self):
        self.ignoreAll()

    def enterReplayLoader(self):
        #self.acceptOnce(event_SINGLEPLAYERGAME, self.demand, ["Menu"]) # enter Menu state
        self.acceptOnce(event_SINGLEPLAYER_MENU, self.demand, ["SinglePlayerGameMenu"]) # enter Menu state

    def exitReplayLoader(self):
        self.ignoreAll()

    def enterMainMenu(self):
        self.ignoreAll()
        messenger.send(event_MAINMENU)